//
//  MSLocationButton.m
//  MSJD
//
//  Created by xiangbo on 2018/11/22.
//  Copyright © 2018 xiangbo. All rights reserved.
//

#import "MSLocationButton.h"

@implementation MSLocationButton

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.titleEdgeInsets = UIEdgeInsetsMake(0.f, 3.f, 0.f, -3);
        self.imageEdgeInsets = UIEdgeInsetsMake(0.f, -3.f, 0.f, 3);
        self.titleLabel.font = [UIFont systemFontOfSize:12];
        [self setTitleColor:UIColorHex(0x444444) forState:UIControlStateNormal];
        [self setImage:[UIImage imageNamed:@"Shape"] forState:UIControlStateNormal];
    }
    return self;
}

-(void)setTitle:(NSString *)title forState:(UIControlState)state{
    self.frame = [self frameWithTitle:title];
    [super setTitle:title forState:state];
}

- (CGRect)frameWithTitle:(NSString *)title{
    CGFloat titleW = [title sizeWithAttributes:@{NSFontAttributeName: self.titleLabel.font}].width;
    CGRect frame = self.frame;
    frame.size.width = titleW + 18;
    return frame;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
